<template>
  <div class="order-list">
    <!-- order-header -->
    <order-header title="订单列表">
      <template v-slot:tip>
        <span>请谨防钓鱼链接或诈骗电话，了解更多</span>
      </template>
    </order-header>
    <!-- 订单列表 -->
    <div class="wrapper">
      <div class="container">
        <div class="order-box">
          <loading v-if="loading"></loading>
          <!-- 每个列表容器 -->
          <div class="order" v-for="(order, index) in list" :key="index">
            <!-- 头部 -->
            <div class="order-title">
              <!-- 信息 -->
              <div class="item-info fl">
                {{ order.createTime }}
                <span>|</span>
                {{ order.receiverName }}
                <span>|</span>
                订单号:{{ order.orderNo }}
                <span>|</span>
                {{ order.paymentTypeDesc }}
              </div>
              <!-- 金额 -->
              <div class="item-money fr">
                <span>应付金额:</span>
                <span class="money">{{ order.payment }}</span>
                <span>元</span>
              </div>
            </div>
            <!-- 内容主体 -->
            <div class="order-content clearfix">
              <!-- 左侧部分 -->
              <div class="good-box fl">
                <!-- 每个列表 -->
                <div
                  class="good-list"
                  v-for="(item, i) in order.orderItemVoList"
                  :key="i"
                >
                  <!-- 图片 -->
                  <div class="good-img">
                    <img v-lazy="item.productImage" alt="" />
                  </div>
                  <!-- 信息 -->
                  <div class="good-name">
                    <!-- 名称 -->
                    <div class="p-name">{{ item.productName }}</div>
                    <!-- 价格 -->
                    <div class="p-money">
                      {{ item.totalPrice + 'X' + item.quantity }}元
                    </div>
                  </div>
                </div>
              </div>
              <!-- 右侧部分,支付状态 -->
              <div class="good-state fr" v-if="order.status == 20">
                <a href="javascript:;">{{ order.statusDesc }}</a>
              </div>
              <div class="good-state fr" v-else>
                <a href="javascript:;" @click="goPay(order.orderNo)">{{
                  order.statusDesc
                }}</a>
              </div>
            </div>
          </div>

          <!-- 分页器 -->
          <el-pagination
            v-if="true"
            class="pagination"
            background
            layout="prev, pager, next"
            :pageSize="pageSize"
            :total="total"
            @current-change="handleChange"
          ></el-pagination>
          <!-- NoData -->
          <no-data v-if="!loading && list.length == 0"></no-data>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import OrderHeader from './../components/OrderHeader'
import Loading from './../components/Loading'
import NoData from './../components/NoData'
import { Pagination, Button } from 'element-ui'
export default {
  name: 'order-list',
  components: {
    OrderHeader,
    Loading,
    NoData,
    [Pagination.name]: Pagination,
    [Button.name]: Button,
  },
  data() {
    return {
      loading: false, //控制显示 lading
      list: [], // 订单列表数据
      pageSize: 10, // 分页器一页显示多少条
      pageNum: 1, // 当前在第几页
      total: 0,
    }
  },
  mounted() {
    this.getOrderList()
  },
  methods: {
    // 获取订单列表
    getOrderList() {
      this.loading = true
      this.busy = true
      this.axios
        .get('/orders', {
          params: {
            pageSize: 10,
            pageNum: this.pageNum,
          },
        })
        .then((res) => {
          this.loading = false
          this.list = this.list.concat(res.list)
          this.total = res.total
        })
        .catch(() => {
          this.loading = false
        })
    },
    // 去支付
    goPay(orderNo) {
      this.$router.push({
        path: '/order/pay',
        query: {
          orderNo,
        },
      })
    },
    // 分页器事件
    handleChange(pageNum) {
      this.pageNum = pageNum
      this.getOrderList()
    }
  },
}
</script>

<style lang="scss">
@import './../assets/scss/config.scss';
@import './../assets/scss/mixin.scss';
.order-list {
  .wrapper {
    background-color: $colorJ;
    padding-top: 33px;
    padding-bottom: 110px;
    .order-box {
      .order {
        @include border();
        background-color: $colorG;
        margin-bottom: 31px;
        &:last-child {
          margin-bottom: 0;
        }
        // 头部
        .order-title {
          @include height(74px);
          background-color: $colorK;
          padding: 0 43px;
          font-size: 16px;
          color: $colorC;
          // 信息
          .item-info {
            // 分割线
            span {
              margin: 0 9px;
            }
          }
          // 金额
          .money {
            font-size: 26px;
            color: $colorB;
          }
        }
        // 内容主体
        .order-content {
          padding: 0 43px;
          // 左侧部分
          .good-box {
            width: 88%;
            .good-list {
              display: flex;
              align-items: center;
              height: 145px;
              .good-img {
                width: 112px;
                img {
                  width: 100%;
                }
              }
              .good-name {
                font-size: 20px;
                color: $colorB;
              }
            }
          }
          // 右侧部分
          .good-state {
            @include height(145px);
            font-size: 20px;
            color: $colorA;
            a {
              color: $colorA;
            }
          }
        }
      }
      .pagination {
        text-align: right;
      }
      .el-pagination.is-background .el-pager li:not(.disabled).active {
        background-color: #ff6600;
      }
      .el-button--primary {
        background-color: #ff6600;
        border-color: #ff6600;
      }
      // 加载更多
      .load-more,
      .scroll-more {
        text-align: center;
      }
    }
  }
}
</style>